/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entidades;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Damian
 */
@Entity
@Table(name = "district")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "District.findAll", query = "SELECT d FROM District d"),
    @NamedQuery(name = "District.findByIdDistrict", query = "SELECT d FROM District d WHERE d.districtPK.idDistrict = :idDistrict"),
    @NamedQuery(name = "District.findByIdCity", query = "SELECT d FROM District d WHERE d.districtPK.idCity = :idCity"),
    @NamedQuery(name = "District.findByName", query = "SELECT d FROM District d WHERE d.name = :name")})
public class District implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DistrictPK districtPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "NAME")
    private String name;
    @JoinColumn(name = "ID_CITY", referencedColumnName = "ID_CITY", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private City city;

    public District() {
    }

    public District(DistrictPK districtPK) {
        this.districtPK = districtPK;
    }

    public District(DistrictPK districtPK, String name) {
        this.districtPK = districtPK;
        this.name = name;
    }

    public District(int idDistrict, int idCity) {
        this.districtPK = new DistrictPK(idDistrict, idCity);
    }

    public DistrictPK getDistrictPK() {
        return districtPK;
    }

    public void setDistrictPK(DistrictPK districtPK) {
        this.districtPK = districtPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (districtPK != null ? districtPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof District)) {
            return false;
        }
        District other = (District) object;
        if ((this.districtPK == null && other.districtPK != null) || (this.districtPK != null && !this.districtPK.equals(other.districtPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entidades.District[ districtPK=" + districtPK + " ]";
    }
    
}
